<template>
  <div class="container">
    <topTitle
      :titleText="titleText"
      :back="back"
      @gobackTriser="goBack"
    ></topTitle>
    <div class="mainCon">
      <el-form
        :model="formData"
        ref="formData"
        :rules="formRules"
        label-width="164px"
        class="demo-ruleForm"
      >
        <!-- <el-row>
                    <el-col>
                        <div class="infoTitle" v-show="domain != 'JZ'">
                            单位信息
                        </div>
                        <div class="infoTitle" v-show="domain == 'JZ'">
                            项目信息
                        </div>
                    </el-col>
                </el-row> -->
        <div
          class="secondaryTitle secondaryTitleTheme mrB30"
          v-show="domain == 'JZ'"
        >
          项目信息
        </div>
        <div
          class="secondaryTitle secondaryTitleTheme mrB30"
          v-show="domain != 'JZ'"
        >
          单位信息
        </div>
        <el-row v-if="domain != 'JZ'" style="margin-bottom: 8px">
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="companyName" label="单位名称：">
                    <el-input
                      v-model.trim="formData.companyName"
                      placeholder="请输入单位完整名称"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.name ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="industryId" label="所属行业：">
                    <el-cascader
                      ref="industry"
                      v-model="formData.industryId"
                      :options="industryOptionsNC"
                      @change="getIndustryId"
                      :props="{ checkStrictly: true }"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.industryId ? true : false"
                      :append-to-body="false"
                    ></el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="boss" label="法人代表：">
                    <el-input
                      v-model.trim="formData.boss"
                      placeholder="请输入法人代表"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.boss ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="bossTel" label="联系电话：">
                    <el-input
                      v-model.trim="formData.bossTel"
                      placeholder="请输入联系电话"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.bossTel ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="uscc" label="统一社会信用代码：">
                    <el-input
                      v-model.trim="formData.uscc"
                      placeholder="请输入统一社会信用代码"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.uscc ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="工商登记执照号码：">
                    <el-input
                      v-model.trim="formData.licenseCode"
                      placeholder="请输入工商登记执照号码"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="officeAddress" label="单位地址：">
                    <el-input
                      v-model.trim="formData.officeAddress"
                      placeholder="请输入单位地址"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="companyInfo.officeAddress ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="landlineTel" label="联系方式：">
                    <el-input
                      v-model.trim="formData.landlineTel"
                      placeholder="请输入联系方式"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="劳资负责人：">
                    <el-input
                      v-model.trim="formData.laborLeader"
                      placeholder="请输入劳资负责人"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="laborLeaderTel" label="联系电话：">
                    <el-input
                      v-model.trim="formData.laborLeaderTel"
                      placeholder="请输入联系电话"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <el-row v-if="domain == 'JZ'" style="margin-bottom: 8px">
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="projectName" label="项目名称：">
                    <el-input
                      v-model.trim="formData.projectName"
                      placeholder="请输入项目完整名称"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="projectInfo.projectName ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="address" label="项目地址：">
                    <el-input
                      v-model.trim="formData.address"
                      placeholder="请输入项目地址"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="projectInfo.address ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="pbName" label="施工方：">
                    <el-input
                      v-model.trim="formData.pbName"
                      placeholder="请输入施工方"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="projectInfo.pbName ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="pcName" label="建设方：">
                    <el-input
                      v-model.trim="formData.pcName"
                      placeholder="请输入建设方"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="projectInfo.pcName ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="industryId" label="所属行业：">
                    <el-select
                      v-model="formData.industryId"
                      filterable
                      placeholder="请选择"
                      class="inputWidth"
                      clearable
                      :disabled="projectInfo.industryId ? true : false"
                      :popper-append-to-body="false"
                    >
                      <el-option
                        v-for="item in industryOptions"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="investment" label="投资类型：">
                    <el-select
                      v-model="formData.investment"
                      filterable
                      placeholder="请选择"
                      class="inputWidth"
                      clearable
                      :disabled="projectInfo.investment ? true : false"
                      :popper-append-to-body="false"
                    >
                      <el-option
                        v-for="item in investmentOptions"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目负责人：">
                    <el-input
                      v-model.trim="formData.leader"
                      placeholder="请输入项目负责人"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="leaderTel" label="联系方式：">
                    <el-input
                      v-model.trim="formData.leaderTel"
                      placeholder="请输入联系方式"
                      class="inputWidth"
                      clearable
                      filterable
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <!-- <el-row>
                    <el-col>
                        <div class="infoTitle">
                            巡查登记
                        </div>
                    </el-col>
                </el-row> -->
        <el-divider></el-divider>
        <div
          class="secondaryTitle secondaryTitleTheme mrB30"
          style="margin-top: 24px"
        >
          巡查登记
        </div>
        <el-row style="margin-bottom: 10px">
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="inspectionDate" label="巡查日期：">
                    <el-date-picker
                      type="date"
                      placeholder="请选择"
                      v-model="formData.inspectionDate"
                      class="inputWidth"
                      clearable
                      value-format="yyyy-MM-dd"
                      :append-to-body="false"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="inspectionPerson" label="巡查员：">
                    <el-input
                      v-model.trim="formData.inspectionPerson"
                      placeholder="请输入巡查员"
                      class="inputWidth"
                      clearable
                      filterable
                      :disabled="formData.inspectionPerson ? true : false"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <!-- <el-form-item label="巡查内容"> -->
                  <div class="tableTitle fl">
                    <span class="star">*</span
                    ><span class="label">巡查内容：</span>
                  </div>
                  <el-table
                    :data="formData.tableList"
                    v-loading="loading"
                    max-height="500"
                    class="tableBoxCon fl"
                    :header-cell-style="{
                      background: '#eef1f6',
                      color: '#606266',
                    }"
                    highlight-current-row
                    stripe
                    style="border: 1px solid #dfe6ec"
                  >
                    <el-table-column
                      type="index"
                      label="序号"
                      width="80px"
                    ></el-table-column>
                    <el-table-column
                      prop="typeName"
                      label="事项类型"
                      min-width="180px"
                    ></el-table-column>
                    <el-table-column
                      prop="itemName"
                      label="巡查项"
                      min-width="180px"
                    ></el-table-column>
                    <el-table-column
                      prop="value"
                      label="巡查结果"
                      min-width="140px"
                    >
                      <template slot-scope="scope">
                        <el-form-item
                          :prop="'tableList.' + scope.$index + '.value'"
                          :rules="formRules[scope.row.resultType]"
                          label-width="0"
                          style="margin: 6px 0 6px 0"
                        >
                          <div
                            @change="
                              {
                                {
                                  changeNum(
                                    scope.$index,
                                    scope.row.resultType,
                                    scope.row.value
                                  )
                                }
                              }
                            "
                          >
                            <template v-if="scope.row.resultType == 'TEXT'">
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入文本"
                                class="inputWidth"
                              ></el-input>
                            </template>
                            <template
                              v-if="scope.row.resultType == 'SINGLE_CHOOSE'"
                            >
                              <el-radio-group v-model="scope.row.value">
                                <el-radio
                                  :label="item"
                                  v-for="(item, index) of scope.row
                                    .resultTypeList"
                                  :key="index"
                                ></el-radio>
                              </el-radio-group>
                            </template>
                            <template
                              v-if="scope.row.resultType == 'MULTIPLE_CHOOSE'"
                            >
                              <el-checkbox-group v-model="checkBoxArr">
                                <el-checkbox
                                  :label="item"
                                  v-for="(item, index) of scope.row
                                    .resultTypeList"
                                  :key="index"
                                  >{{ item }}</el-checkbox
                                >
                              </el-checkbox-group>
                            </template>
                            <template
                              v-if="scope.row.resultType == 'POPULATION'"
                            >
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入人数"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;人
                            </template>
                            <template
                              v-if="scope.row.resultType == 'PERCENTAGE'"
                            >
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入比例数"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;%
                            </template>
                            <template v-if="scope.row.resultType == 'MONEY'">
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入金额"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;元
                            </template>
                            <template v-if="scope.row.resultType == 'AMOUNT'">
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入数量"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;个
                            </template>
                            <template v-if="scope.row.resultType == 'DAYS'">
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入天数"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;天
                            </template>
                            <template v-if="scope.row.resultType == 'HOURS'">
                              <el-input
                                v-model="scope.row.value"
                                placeholder="请输入小时数"
                                class="inputWidth"
                              ></el-input
                              >&nbsp;小时
                            </template>
                            <template v-if="scope.row.resultType == 'DATE'">
                              <el-date-picker
                                @change="
                                  {
                                    {
                                      changeNumDate(
                                        scope.$index,
                                        scope.row.resultType,
                                        scope.row.value
                                      )
                                    }
                                  }
                                "
                                type="date"
                                placeholder="请选择日期"
                                v-model="scope.row.value"
                                class="inputWidth"
                                value-format="yyyy-MM-dd"
                              ></el-date-picker>
                            </template>
                          </div>
                        </el-form-item>
                      </template>
                    </el-table-column>
                    <el-table-column label="凭证上传" width="110">
                      <template slot-scope="scope">
                        <el-link
                          type="primary"
                          @click="toUploadFile(scope.$index, scope.row)"
                          >上传</el-link
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                  <!-- </el-form-item> -->
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <!-- <el-row>
                    <el-col>
                        <div class="infoTitle">
                            巡查结果
                        </div>
                    </el-col>
                </el-row> -->
        <el-divider></el-divider>
        <div
          class="secondaryTitle secondaryTitleTheme mrB30"
          style="margin-top: 24px"
        >
          巡查结果
        </div>
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="inspectionResult" label="巡查结果：">
                    <el-select
                      v-model="formData.inspectionResult"
                      placeholder="请选择"
                      @change="resultTypeChange"
                      class="inputWidth"
                      clearable
                      :popper-append-to-body="false"
                    >
                      <el-option
                        label="存在问题，需整改"
                        value="YES"
                      ></el-option>
                      <el-option
                        label="无问题，无需整改"
                        value="NO"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="rectificationDate" label="整改期限：">
                    <el-date-picker
                      type="date"
                      placeholder="请选择"
                      v-model="formData.rectificationDate"
                      :disabled="dateDisabled"
                      class="inputWidth"
                      clearable
                      value-format="yyyy-MM-dd"
                      :append-to-body="false"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <el-form-item prop="inspectionProblem" label="存在问题：">
                    <el-input
                      type="textarea"
                      v-model.trim="formData.inspectionProblem"
                      placeholder="请输入存在问题"
                      class="textareaBox"
                      clearable
                      filterable
                      maxlength="500"
                      :rows="4"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <el-row style="text-align: center; margin-top: 45px">
          <el-col :span="20">
            <el-form-item>
              <el-button
                class="commonBut saveBtn"
                type="primary"
                @click="savePermission"
                :loading="isSaveLoading"
                v-sdc
                >创建</el-button
              >
              <el-button class="commonBut cancelBtn" @click="goBack" v-sdc
                >取消</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 上传合同附件 -->
    <el-dialog
      title="附件"
      :visible.sync="uploadContract"
      width="900px"
      :modal-append-to-body="false"
    >
      <uploadAnnex
        :limitationFactor="limitationFactor"
        @getFile="getFile"
        :upLoadFile="uploadImg"
      />
      <div style="margin-top: 10px">
        <contractEnclosure
          :tableData="uploadImg"
          isDel="true"
          @changeFileList="changeFileList"
        ></contractEnclosure>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex'

export default {
  name: 'patrolAddNext',
  data() {
    //验证uscc
    var validateUscc = (rule, value, callback) => {
      value = value.replace(/\s+/g, '')
      if (value === '') {
        callback(new Error('统一社会信用代码不能为空'))
      } else {
        var regUscc = /^[0-9A-Z]{2}[0-9]{6}[0-9A-Z]{10}$/
        if (!regUscc.test(value)) {
          callback(new Error('统一社会信用代码格式不正确'))
        } else {
          callback()
        }
      }
    }
    var validateRectificationDate = (rule, value, callback) => {
      if (this.dateDisabled == true) {
        callback()
      } else {
        if (!value) {
          callback(new Error('请选择整改日期'))
        } else {
          callback()
        }
      }
    }
    var validateProblem = (rule, value, callback) => {
      if (value.length > 500) {
        callback(new Error('输入内容不能超过500个字符'))
      } else {
        callback()
      }
    }
    var validDay = (rule, value, callback) => {
      var reDay = /^(([1-9][0-9]*)|(([0]\.\d{1}|[1-9][0-9]*\.\d{1}))|0)$/
      if (!reDay.test(value) || value === '0.0') {
        callback(new Error('请输入正确的天数'))
      } else {
        callback()
      }
    }
    var validHour = (rule, value, callback) => {
      var reDay = /^(([1-9][0-9]*)|(([0]\.\d{1}|[1-9][0-9]*\.\d{1}))|0)$/
      if (!reDay.test(value) || value === '0.0') {
        callback(new Error('请输入正确的小时数'))
      } else {
        callback()
      }
    }
    return {
      show: false,
      titleText: '创建巡查',
      back: true,
      setp: 1,
      radio: '',
      industryId: '',
      formData: {
        companyId: '',
        projectId: '',
        companyName: '',
        industryId: '',
        boss: '',
        bossTel: '',
        uscc: '',
        licenseCode: '',
        officeAddress: '',
        landlineTel: '',
        laborLeader: '',
        laborLeaderTel: '', //以上企业信息
        projectName: '',
        address: '',
        pbName: '',
        pcName: '',
        // industryId: "",
        investment: '',
        leader: '',
        leaderTel: '', //以上项目信息
        inspectionDate: '',
        inspectionPerson: '',
        tableList: [],
        inspectionResult: '',
        rectificationDate: '',
        inspectionProblem: '',
      },
      checkBoxArr: [], //复选
      projectInfo: {}, //项目信息
      companyInfo: {}, //企业信息
      formRules: {
        //企业
        companyName: [
          { required: true, message: '单位名称不能为空', trigger: 'change' },
        ],
        boss: [{ required: true, message: '请输入法人代表', trigger: 'blur' }],
        bossTel: [
          {
            required: false,
            pattern: /^1[3456789]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
          },
        ],
        uscc: [{ required: true, validator: validateUscc, trigger: 'change' }],
        officeAddress: [
          { required: true, message: '请输入单位地址', trigger: 'blur' },
        ],
        laborLeaderTel: [
          {
            required: false,
            pattern: /^1[3456789]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
          },
        ],
        landlineTel: [
          {
            required: true,
            pattern: /0\d{2,3}-\d{7,8}/,
            message: '请输入正确的座机号码',
            trigger: 'blur',
          },
        ],
        // 项目
        projectName: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' },
        ],
        address: [
          { required: true, message: '请输入项目地址', trigger: 'blur' },
        ],
        pbName: [{ required: true, message: '请输入施工方', trigger: 'blur' }],
        pcName: [{ required: true, message: '请输入建设方', trigger: 'blur' }],
        industryId: [
          { required: true, message: '所属行业不能为空', trigger: 'change' },
        ],
        investment: [
          { required: true, message: '投资类型不能为空', trigger: 'change' },
        ],
        leaderTel: [
          {
            required: false,
            pattern: /^1[3456789]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
          },
        ],
        //通用
        inspectionDate: [
          { required: true, message: '巡查日期不能为空', trigger: 'change' },
        ],
        inspectionPerson: [
          { required: true, message: '请输入巡查员', trigger: 'blur' },
        ],
        inspectionResult: [
          { required: true, message: '请选择巡查结果', trigger: 'change' },
        ],
        rectificationDate: [
          {
            required: true,
            validator: validateRectificationDate,
            trigger: 'change',
          },
        ],
        TEXT: [{ required: true, message: '请输入文本', trigger: 'blur' }],
        SINGLE_CHOOSE: [{ required: true, message: '请选择', trigger: 'blur' }],
        MULTIPLE_CHOOSE: [
          { required: true, message: '请选择', trigger: 'blur' },
        ],
        POPULATION: [
          {
            required: true,
            pattern: /^[\+]?(([1-9]\d*)|\d)$/,
            message: '请输入正确的人数',
            trigger: 'blur',
          },
        ],
        PERCENTAGE: [
          {
            required: true,
            pattern: /^(([1-9]\d*)(\.\d{1,2})?|0\.([1-9]|\d[1-9])|0)$/,
            message: '请输入正确的比例数',
            trigger: 'blur',
          },
        ],
        MONEY: [
          {
            required: true,
            pattern: /^(([1-9]\d*)(\.\d{1,2})?|0\.([1-9]|\d[1-9])|0)$/,
            message: '请输入正确的金额',
            trigger: 'blur',
          },
        ],
        AMOUNT: [
          {
            required: true,
            pattern: /^(([1-9]\d*)(\.\d{1,2})?|0\.([1-9]|\d[1-9])|0)$/,
            message: '请输入正确的数量',
            trigger: 'blur',
          },
        ],
        DAYS: [{ required: true, validator: validDay, trigger: 'blur' }],
        HOURS: [{ required: true, validator: validHour, trigger: 'blur' }],
        DATE: [{ required: true, message: '请选择日期', trigger: 'blur' }],
        inspectionProblem: [
          { required: false, validator: validateProblem, trigger: 'blur' },
        ],
      },
      isDisabled: false, //默认不禁用，如果有值带入则禁用
      dateDisabled: false, //整改日期禁用
      uploadImg: [], //附件
      uploadContract: false, //上传合同附件
      canLogin: false, //保存loading
      limitationFactor: {
        uploadAnnexUrl: 'api-f/files/upload', //自定义上传文件接口地址
        upLoadFileLength: 10, //自定义上传附件的个数设置
        fileSize: 5, //自定义上传文件最大设置
        formatType: 'typeFour', //自定义上传格式校验类型
        fileId: 'salaryExcel', //自定义id解决一个页面包含多个上传附件
        uploadFormId: 'salaryExcelForm', //自定义id解决一个页面包含多个上传附件
        messagetip:
          '要求格式为png，jpg，jpeg，doc，docx，xls，xlsx，pdf格式，附件大小不超过5M', //自定义报错提示语
        methodTip:
          '附件格式支持png，jpg，jpeg，doc，docx，xls，xlsx，pdf,最多上传10个附件', //自定义上传文件提示
        uploadBtnType: 'typeTwo', //自定义上传按钮类型
        UploadType: 'typeTwo',
      },
      domain: '', //区分建筑与非建
      id: '', //企业，项目id
      fileIndex: '', //附件索引
      isSaveLoading: false, // 保存loading
      taskId: '', //执行任务Id
      taskType: '',
    }
  },
  computed: {
    ...mapState(['industryOptions', 'investmentOptions', 'industryOptionsNC']),
  },
  created() {
    this.domain = this.$route.query.domain
    this.taskId = this.$route.query.taskId
    this.taskType = this.$route.query.taskType
    this.getDraginDetail()
  },
  methods: {
    goBack() {
      this.$router.push({
        path: '/home/patrol/patrolAddFirst',
        name: 'patrolAddFirst',
        query: {
          domain: this.domain,
          taskType: this.taskType,
        },
      })
      this.tabChoose()
    },
    changeNum(index, resultType, value) {
      this.formData.tableList[index].value = value
      //复选框是数组，单独处理
      if (resultType == 'MULTIPLE_CHOOSE') {
        this.formData.tableList[index].value = this.checkBoxArr
      }
    },
    changeNumDate(index, resultType, value) {
      this.formData.tableList[index].value = value
    },
    // 查询企业/项目带入信息
    getDraginDetail(id) {
      this.axios({
        method: 'post',
        url: 'api-gov/ipqccompany/ipqcCreateInit',
        data: {
          taskId: this.taskId,
        },
      })
        .then((response) => {
          if (!response.data.hasError) {
            var data = response.data.result
            //项目信息
            this.formData.inspectionPerson = data.jobUser
            this.formData.tableList = data.items
            if (data.fieldType == 'CS') {
              //加{} 防止后台返回值类型错误导致前端报错
              this.projectInfo = data.projectInfo || {}
              //有值则带入无法修改
              this.formData.projectId = this.projectInfo.id
              this.formData.projectName = this.projectInfo.projectName
              this.formData.address = this.projectInfo.address
              this.formData.pbName = this.projectInfo.pbName
              this.formData.pcName = this.projectInfo.pcName
              this.formData.industryId = this.projectInfo.industryId
              this.formData.investment = this.projectInfo.investment
            } else {
              //企业信息
              this.companyInfo = data.companyInfo || {}
              //有值则带入无法修改
              this.formData.companyId = this.companyInfo.id
              this.formData.companyName = this.companyInfo.name
              this.formData.industryId = this.companyInfo.industryId
              this.formData.boss = this.companyInfo.boss
              this.formData.bossTel = this.companyInfo.bossTel
              this.formData.uscc = this.companyInfo.uscc
              this.formData.officeAddress = this.companyInfo.officeAddress
              this.formData.landlineTel = this.companyInfo.landlineTel
            }
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {})
    },
    savePermission() {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          // 保存更新
          this.submitFormAdd()
        } else {
          return false
        }
      })
    },
    submitFormAdd() {
      var data = {}
      var url = ''
      if (this.domain == 'JZ') {
        data = {
          taskId: this.taskId,
          projectId: this.formData.projectId,
          projectName: this.formData.projectName,
          address: this.formData.address,
          pbName: this.formData.pbName,
          pcName: this.formData.pcName,
          industryId: this.formData.industryId,
          investment: this.formData.investment,
          leader: this.formData.leader,
          leaderTel: this.formData.leaderTel,
          inspectionDate: this.formData.inspectionDate,
          inspectionPerson: this.formData.inspectionPerson,
          inspectionResult: this.formData.inspectionResult,
          rectificationDate: this.formData.rectificationDate,
          inspectionProblem: this.formData.inspectionProblem,
          ipqcItemList: JSON.stringify(this.formData.tableList),
          licenseCode: this.formData.licenseCode,
        }
        url = 'api-gov/ipqcproject/addIpqcProject'
      } else {
        data = {
          taskId: this.taskId,
          companyId: this.formData.companyId,
          companyName: this.formData.companyName,
          industryId: this.formData.industryId,
          boss: this.formData.boss,
          bossTel: this.formData.bossTel,
          uscc: this.formData.uscc,
          organizationCode: this.formData.organizationCode,
          address: this.formData.officeAddress,
          contactType: this.formData.landlineTel,
          laborLeader: this.formData.laborLeader,
          laborLeaderTel: this.formData.laborLeaderTel,
          inspectionDate: this.formData.inspectionDate,
          inspectionPerson: this.formData.inspectionPerson,
          inspectionResult: this.formData.inspectionResult,
          rectificationDate: this.formData.rectificationDate,
          inspectionProblem: this.formData.inspectionProblem,
          ipqcItemList: JSON.stringify(this.formData.tableList),
          licenseCode: this.formData.licenseCode,
        }
        url = 'api-gov/ipqccompany/addIpqcCompany'
      }
      this.isSaveLoading = true
      this.axios({
        method: 'post',
        url: url,
        data: data,
      })
        .then((response) => {
          this.isSaveLoading = false
          if (!response.data.hasError) {
            this.$message({
              message: response.data.msg,
              type: 'success',
            })
            var path =
              this.taskType == 'SPECIAL'
                ? '/home/patrol/patrolListSpecial'
                : '/home/patrol/patrolList'
            var name =
              this.taskType == 'SPECIAL' ? 'patrolListSpecial' : 'patrolList'
            this.$router.push({
              path,
              name,
              query: {
                domain: this.domain,
                taskType: this.taskType,
              },
            })
            this.tabChoose()
          } else {
            this.$message({
              type: 'error',
              message: response.data.errorMsg,
            })
            this.isSaveLoading = false
          }
        })
        .catch((error) => {
          this.$message.error('创建失败')
          this.isSaveLoading = false
        })
    },
    resultTypeChange() {
      //无问题，无需整改,整改期限无法填写 NO
      if (this.formData.inspectionResult == 'NO') {
        this.formData.rectificationDate = ''
        this.dateDisabled = true
      } else {
        this.dateDisabled = false
      }
    },
    //附件上传
    toUploadFile(index, row) {
      if (!row.disburseFile) {
        this.uploadImg = []
      } else {
        this.uploadImg = row.disburseFile
      }
      this.uploadContract = true
      this.fileIndex = index
    },
    getFile(val) {
      this.uploadImg.push(val)
      this.getNewFile()
    },
    changeFileList(val) {
      this.uploadImg = val
      this.getNewFile()
    },
    getNewFile() {
      var arr = []
      this.uploadImg.forEach((items) => {
        arr.push({
          name: items.name,
          path: items.path,
          size: items.size,
          fileType: items.contentType,
          createTime: items.createTime,
        })
      })
      this.formData.tableList[this.fileIndex].disburseFile = []
      this.formData.tableList[this.fileIndex].disburseFile = arr
    },
    //日常、专项tab 选中问题
    tabChoose() {
      var oldUrl =
        this.taskType == 'SPECIAL'
          ? '/home/patrol/patrolListSpecial'
          : '/home/patrol/patrolList'
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: oldUrl,
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //获取选中的行业最后一级id
    getIndustryId() {
      var industryId = this.industryId[this.industryId.length - 1]
      this.formData.industryId = industryId
    },
  },
}
</script>

<style lang="less" scoped>
.mainCon {
  top: 198px;
  padding: 24px;
  .infoTitle {
    font-size: 16px;
    padding: 16px 24px;
    background: #f5f7fb;
    margin-bottom: 24px;
    color: #333;
    font-weight: 700;
  }
  .inputWidth {
    width: 65%;
  }
  .tableTitle {
    vertical-align: top;
    width: 164px;
    color: #333333;
    text-align: right;
    font-size: 14px;
    .star {
      color: #f56c6c;
      margin-right: 4px;
    }
    .label {
      margin-right: 12px;
    }
  }
  .tableBoxCon {
    width: calc(94% - 150px);
    margin-bottom: 20px;
  }
  .textareaBox {
    width: 93.5%;
  }
}
</style>
